package com.sun.web.controller;

import com.sun.mapper.UserMapper;
import com.sun.entity.User;
import com.sun.web.exception.CustomException;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by pullFoot_youth on 2017/2/23.
 */
@Controller
@RequestMapping("")
public class LoginController {


    @Autowired
    private UserMapper um;

//    @Autowired
//    private CacheUtils cacheUtils;

    @RequestMapping("/login")
    public Object login(String id) throws CustomException {

//        log.info("测试git回滚到上一版本");
        int i = 1/0;

        if(StringUtils.isEmpty(id)){
            throw new CustomException("id值不能为空");
        }

        return "/login";
    }

    @RequestMapping("/test")
    @ResponseBody
    public Object index(User user){

//        User user = um.findById("dac85ab2-ff50-11e6-a926-08606edd245d");

//        return user1;

        return user;

    }


    @RequestMapping("hello")
    public String hello(HttpSession session){


//        Student s = studentMapper.selectByPrimaryKey(1);
//
//        System.out.println(s.toString());

//        EhCacheManager ehcacheManager = cacheUtils.getEhCacheManager();
//
//        org.apache.shiro.cache.Cache cache = ehcacheManager.getCache("shiro-activeSessionCache");
//
//        Set<Object> set = cache.keys();
//
//        System.out.println(set.size());
//        for(Object k:set){
//            Session session1 = (Session)cache.get(k);
//            System.out.println("缓存中的session --" + session1.getId());
//            if("c927b3ea-0043-4e96-b512-d32fe7747ba9".equals(session1.getId())){
//                cache.remove(session1.getId());
//            }
//        }
//        Set<Object> newSet = cache.keys();
//
//        System.out.println(newSet.size());
//
//        for(Object k:newSet){
//            Session nsession1 = (Session)cache.get(k);
//            System.out.println("清除后的缓存 session --" + nsession1.getId());
//
//        }
//
//        Session session1 =  (Session) cache.get(session.getId());

        return "/hello";
    }

}
